﻿package com.tudou.home.view.ad
{
    import com.tudou.home.commands.ad.*;
    import com.tudou.home.consts.*;
    import com.tudou.home.view.ad.base.*;
    import com.tudou.utils.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;

    public class AdLoadingMediator extends AdBaseMediator implements IAdMediator
    {
        private var maskShape:Shape;
        public static const NAME:String = "AdLoadingMediator";

        public function AdLoadingMediator(param1:Sprite)
        {
            super(NAME, param1);
            init();
            return;
        }// end function

        override public function showAd() : void
        {
            viewBox.visible = true;
            sendNotification(AdLoadingCommandSet.LOADING_SHOW_START);
            return;
        }// end function

        override public function setAdDisplay(param1:DisplayObject, param2:DisplayObject = null) : void
        {
            var primaryAd:* = param1;
            var additinalAd:* = param2;
            if (primaryAd == null)
            {
                return;
            }
            this.primaryAd = primaryAd;
            viewBox.addChild(primaryAd);
            try
            {
                viewBox.addEventListener(MouseEvent.CLICK, mouseEventHandler);
            }
            catch (error:Error)
            {
            }
            return;
        }// end function

        override public function hideAd() : void
        {
            viewBox.visible = false;
            sendNotification(AdLoadingCommandSet.LOADING_SHOW_COMPLETE);
            return;
        }// end function

        override public function goTransform(param1:uint, param2:uint, param3:Boolean) : void
        {
            viewBox.x = int((param1 - AdSize.LOADING_WIDTH) / 2);
            viewBox.y = int((param2 - AdSize.LOADING_HEIGHT) / 2);
            return;
        }// end function

        private function mouseEventHandler(event:Event) : void
        {
            sendNotification(AdLoadingCommandSet.LOADING_CLICK);
            return;
        }// end function

        private function init() : void
        {
            viewBox.buttonMode = true;
            maskShape = RectDisplayUtil.getShape(AdSize.LOADING_WIDTH, AdSize.LOADING_HEIGHT);
            viewBox.addChild(maskShape);
            viewBox.mask = maskShape;
            var _loc_1:* = PlayerConsts.NORMALSCREEN_RECT;
            goTransform(_loc_1.width, _loc_1.height, false);
            return;
        }// end function

        override public function clearAd() : void
        {
            super.clearAd();
            _adItemInfo = null;
            _adThrowInfo = null;
            viewBox.removeEventListener(MouseEvent.CLICK, mouseEventHandler);
            primaryAd = null;
            while (viewBox.numChildren > 0)
            {
                
                viewBox.removeChildAt(0);
            }
            viewBox.addChild(maskShape);
            hideAd();
            return;
        }// end function

        override public function getAdDisplay() : DisplayObject
        {
            return viewBox;
        }// end function

    }
}
